package cn.donghuapian.service.impl;

import cn.donghuapian.entity.WarEntity;
import cn.donghuapian.mapper.WarMapper;
import cn.donghuapian.service.IWarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hzw
 * @since 2024-09-04
 */
@Service
public class WarServiceImpl extends ServiceImpl<WarMapper, WarEntity> implements IWarService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public List<WarEntity> list() {
        return super.list();
    }

    public void send() {
        for (int i = 0; i < 20; i++) {
            rabbitTemplate.convertAndSend("厄斐琉斯", i);
        }
    }

    public void sendFanout() {
        rabbitTemplate.convertAndSend("testFanout", "cc", 1);
//        for (int i = 0; i < 4; i++) {
//            rabbitTemplate.convertAndSend("testFanout", "cc", i);
//        }

    }

    public void exchangeDirect() {
        for (int i = 0; i < 4; i++) {
            rabbitTemplate.convertAndSend("exchangeDirect", "cc", i);
        }

    }

    public void deadQueue() {
        for (int i = 0; i < 4; i++) {
            rabbitTemplate.convertAndSend("normalQueue", i);
        }
        rabbitTemplate.convertAndSend("normalQueue", "deadTest");
    }

    public void delayQueue() {
        for (int i = 0; i < 4; i++) {
            rabbitTemplate.convertAndSend("delayQueue", i);
        }
    }

    public void testCircuitBreaker() {
        for (int i = 0; i < 50000; i++) {
            rabbitTemplate.convertAndSend("aurelionSol", i);
        }
    }
}
